<template>
  <div class="auth-container">
    <div class="auth-box">
      <!-- 切换按钮 -->
      <div class="switch-buttons">
        <button 
          :class="{ active: !isRegister }" 
          @click="isRegister = false"
        >登录</button>
        <button 
          :class="{ active: isRegister }" 
          @click="isRegister = true"
        >注册</button>
        <div class="switch-indicator" :class="{ right: isRegister }"></div>
      </div>

      <!-- 表单容器 -->
      <div class="forms-container">
        <div class="forms-wrapper" :style="{ transform: `translateX(${isRegister ? '-50%' : '0'})` }">
          <!-- 登录表单 -->
          <div class="form login-form">
            <div class="form-header">
              <h2>欢迎回来</h2>
              <p>开启你的音乐之旅</p>
            </div>
            <div class="form-content">
              <!-- 账号输入框 -->
              <div class="input-group">
                <i class="iconfont icon-user"></i>
                <input 
                  type="text" 
                  v-model="loginForm.username"
                  placeholder="请输入账号/手机号/邮箱"
                  @focus="handleFocus"
                  @blur="handleBlur"
                >
                <div class="input-line"></div>
              </div>

              <!-- 密码输入框 -->
              <div class="input-group">
                <i class="iconfont icon-lock"></i>
                <input 
                  :type="showPassword ? 'text' : 'password'"
                  v-model="loginForm.password"
                  placeholder="请输入密码"
                  @focus="handleFocus"
                  @blur="handleBlur"
                >
                <i 
                  class="iconfont toggle-password"
                  :class="showPassword ? 'icon-eye' : 'icon-eye-close'"
                  @click="showPassword = !showPassword"
                ></i>
                <div class="input-line"></div>
              </div>

              <!-- 记住密码和忘记密码 -->
              <div class="form-options">
                <label class="remember-me">
                  <input type="checkbox" v-model="loginForm.remember">
                  <span class="checkmark"></span>
                  <span>记住密码</span>
                </label>
                <a href="#" class="forgot-password">忘记密码？</a>
              </div>

              <!-- 登录按钮 -->
              <button 
                class="submit-btn" 
                @click="handleLogin"
                :class="{ 'loading': isLoading }"
              >
                <span>{{ isLoading ? '登录中...' : '登 录' }}</span>
                <div class="btn-loader"></div>
              </button>

              <!-- 其他登录方式 -->
              <div class="social-login">
                <div class="divider">
                  <span>其他登录方式</span>
                </div>
                <div class="social-icons">
                  <div class="social-icon wechat" @click="socialLogin('wechat')">
                    <i class="iconfont icon-wechat"></i>
                  </div>
                  <div class="social-icon qq" @click="socialLogin('qq')">
                    <i class="iconfont icon-QQ"></i>
                  </div>
                  <div class="social-icon weibo" @click="socialLogin('weibo')">
                    <i class="iconfont icon-weibo"></i>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <!-- 注册表单 -->
          <div class="form register-form">
            <div class="form-header">
              <h2>创建账号</h2>
              <p>加入悦听音乐，开启你的音乐之旅</p>
            </div>
            <div class="form-content">
              <!-- 账号输入框 -->
              <div class="input-group">
                <i class="iconfont icon-user"></i>
                <input 
                  type="text" 
                  v-model="registerForm.username"
                  placeholder="请设置账号"
                  @focus="handleFocus"
                  @blur="handleBlur"
                >
                <div class="input-line"></div>
              </div>

              <!-- 手机号输入框 -->
              <div class="input-group">
                <i class="iconfont icon-phone"></i>
                <input 
                  type="tel" 
                  v-model="registerForm.phone"
                  placeholder="请输入手机号"
                  @focus="handleFocus"
                  @blur="handleBlur"
                >
                <div class="input-line"></div>
              </div>

              <!-- 密码输入框 -->
              <div class="input-group">
                <i class="iconfont icon-lock"></i>
                <input 
                  :type="showRegPassword ? 'text' : 'password'"
                  v-model="registerForm.password"
                  placeholder="请设置密码"
                  @focus="handleFocus"
                  @blur="handleBlur"
                >
                <i 
                  class="iconfont toggle-password"
                  :class="showRegPassword ? 'icon-eye' : 'icon-eye-close'"
                  @click="showRegPassword = !showRegPassword"
                ></i>
                <div class="input-line"></div>
              </div>

              <!-- 确认密码 -->
              <div class="input-group">
                <i class="iconfont icon-lock"></i>
                <input 
                  :type="showRegPassword ? 'text' : 'password'"
                  v-model="registerForm.confirmPassword"
                  placeholder="请确认密码"
                  @focus="handleFocus"
                  @blur="handleBlur"
                >
                <div class="input-line"></div>
              </div>

              <!-- 用户协议 -->
              <div class="form-options">
                <label class="agree-terms">
                  <input type="checkbox" v-model="registerForm.agreeTerms">
                  <span class="checkmark"></span>
                  <span class="terms-text">
                    我已阅读并同意
                    <a href="#" @click.prevent="showTerms = true">服务条款</a>
                    和
                    <a href="#" @click.prevent="showPrivacy = true">隐私政策</a>
                  </span>
                </label>
              </div>

              <!-- 注册按钮 -->
              <button 
                class="submit-btn" 
                @click="handleRegister"
                :disabled="!canRegister"
                :class="{ 'loading': isRegistering }"
              >
                <span>{{ isRegistering ? '注册中...' : '立即注册' }}</span>
                <div class="btn-loader"></div>
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Auth',
  data() {
    return {
      isRegister: false,
      showPassword: false,
      showRegPassword: false,
      isLoading: false,
      isRegistering: false,
      loginForm: {
        username: '',
        password: '',
        remember: false
      },
      registerForm: {
        username: '',
        phone: '',
        password: '',
        confirmPassword: '',
        agreeTerms: false
      }
    }
  },
  computed: {
    canRegister() {
      return this.registerForm.username &&
             this.registerForm.phone &&
             this.registerForm.password &&
             this.registerForm.password === this.registerForm.confirmPassword &&
             this.registerForm.agreeTerms
    }
  },
  methods: {
    handleFocus(e) {
      e.target.parentElement.classList.add('focused')
    },
    handleBlur(e) {
      if (!e.target.value) {
        e.target.parentElement.classList.remove('focused')
      }
    },
    async handleLogin() {
      if (this.isLoading) return
      
      this.isLoading = true
      try {
        // 模拟登录请求
        await new Promise(resolve => setTimeout(resolve, 1500))
        console.log('Login:', this.loginForm)
        // 登录成功后的处理...
      } catch (error) {
        console.error('Login failed:', error)
      } finally {
        this.isLoading = false
      }
    },
    async handleRegister() {
      if (!this.canRegister || this.isRegistering) return
      
      this.isRegistering = true
      try {
        // 模拟注册请求
        await new Promise(resolve => setTimeout(resolve, 1500))
        console.log('Register:', this.registerForm)
        // 注册成功后的处理...
      } catch (error) {
        console.error('Registration failed:', error)
      } finally {
        this.isRegistering = false
      }
    },
    socialLogin(platform) {
      console.log(`使用 ${platform} 登录`);
      // 这里添加社交登录的具体实现
    }
  }
}
</script>

<style scoped>
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(45deg, #ff9a9e 0%, #fad0c4 99%, #fad0c4 100%);
  padding: 20px;
}

.auth-box {
  width: 100%;
  max-width: 420px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  padding: 40px 30px;
}

/* 切换按钮样式 */
.switch-buttons {
  position: relative;
  display: flex;
  width: 300px;
  margin: 0 auto 30px;
  background: #f5f5f5;
  border-radius: 25px;
  padding: 5px;
}

.switch-buttons button {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  color: #666;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: color 0.3s ease;
}

.switch-buttons button.active {
  color: white;
}

.switch-indicator {
  position: absolute;
  top: 5px;
  left: 5px;
  width: calc(50% - 5px);
  height: calc(100% - 10px);
  background: linear-gradient(45deg, #ff6b6b, #ffd93d);
  border-radius: 20px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.switch-indicator.right {
  transform: translateX(calc(100% + 5px));
}

/* 表单容器样式 */
.forms-container {
  overflow: hidden;
}

.forms-wrapper {
  display: flex;
  width: 200%;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.form {
  width: 50%;
  padding: 0 20px;
}

/* 表单样式 */
.form-header {
  text-align: center;
  margin-bottom: 30px;
}

.form-header h2 {
  font-size: 24px;
  color: #333;
  margin-bottom: 10px;
}

.form-header p {
  color: #666;
  font-size: 14px;
}

.input-group {
  position: relative;
  margin-bottom: 25px;
}

.input-group i {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
  transition: all 0.3s ease;
}

.input-group input {
  width: 100%;
  padding: 12px 20px 12px 45px;
  border: none;
  border-bottom: 2px solid #eee;
  background: transparent;
  font-size: 16px;
  transition: all 0.3s ease;
}

.input-group input:focus {
  outline: none;
}

.input-line {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: linear-gradient(45deg, #ff6b6b, #ffd93d);
  transition: width 0.3s ease;
}

.input-group.focused .input-line {
  width: 100%;
}

.input-group.focused i {
  color: #ff6b6b;
}

.toggle-password {
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  color: #999;
  transition: all 0.3s ease;
}

.toggle-password:hover {
  color: #ff6b6b;
}

/* 表单选项样式 */
.form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
}

.remember-me, .agree-terms {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #666;
  cursor: pointer;
}

.checkmark {
  width: 18px;
  height: 18px;
  border: 2px solid #ddd;
  border-radius: 4px;
  position: relative;
  transition: all 0.3s ease;
}

input[type="checkbox"]:checked + .checkmark {
  background: #ff6b6b;
  border-color: #ff6b6b;
}

.checkmark:after {
  content: '';
  position: absolute;
  display: none;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

input[type="checkbox"]:checked + .checkmark:after {
  display: block;
}

.forgot-password {
  color: #ff6b6b;
  text-decoration: none;
  font-size: 14px;
  transition: color 0.3s ease;
}

.forgot-password:hover {
  color: #ff4757;
}

/* 提交按钮样式 */
.submit-btn {
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 25px;
  background: linear-gradient(45deg, #ff6b6b, #ffd93d);
  color: white;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(255, 107, 107, 0.4);
}

.submit-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.btn-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  border: 2px solid white;
  border-top-color: transparent;
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity 0.3s ease;
}

.submit-btn.loading {
  color: transparent;
}

.submit-btn.loading .btn-loader {
  opacity: 1;
  animation: spin 0.8s linear infinite;
}

/* 社交登录样式 */
.social-login {
  margin-top: 30px;
  text-align: center;
}

.divider {
  position: relative;
  margin-bottom: 20px;
}

.divider::before,
.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: calc(50% - 100px);
  height: 1px;
  background: #eee;
}

.divider::before {
  left: 0;
}

.divider::after {
  right: 0;
}

.divider span {
  background: white;
  padding: 0 20px;
  color: #999;
  font-size: 14px;
}

.social-icons {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.social-icon {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.social-icon i {
  font-size: 24px;
  color: white;
}

.social-icon.wechat {
  background: #07c160;
}

.social-icon.qq {
  background: #12b7f5;
}

.social-icon.weibo {
  background: #e6162d;
}

.social-icon:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* 动画效果 */
@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* 响应式调整 */
@media (max-width: 480px) {
  .auth-box {
    padding: 30px 20px;
  }

  .switch-buttons {
    width: 250px;
  }

  .form {
    padding: 0 10px;
  }

  .input-group input {
    font-size: 14px;
  }

  .social-icon {
    width: 40px;
    height: 40px;
  }

  .social-icon i {
    font-size: 20px;
  }
}
</style> 